import VenuesStore from "../store/VenuesStore";
import VenuesService from "../service/VenuesService";
import { ElMessage } from 'element-plus';
import { useRouter } from 'vue-router'
interface adverAction {
    page_Venues:(limit: number, name: string, page: number,count:number)=>void,
    delete_id_venues:(id: number,)=>void,
    add_Venues:(obj: object)=>void,
}
export function venuesHook(): adverAction {
    const router = useRouter()
    console.log(router)
    //查询
    function page_Venues( limit: number, name: string, page: number,count:number):any {
        console.log("111");
        console.log(limit);
        const store = VenuesStore()
        VenuesService.getVenuesPageList(limit, name, page,count).then((res:any)=>{
            console.log(res.data.data);
            store.setList(res.data.data)
        })
    }
    //新增
    // interface VenueInfo {
    //     address?: string;
    //     capacity?: number;
    //     createTime?: string;
    //     deleted?: string;
    //     email?: string;
    //     id: number;
    //     image: string;
    //     introduce: string;
    //     name: string;
    //     phone: number;
    //     state: number;
    //     updateTime: string;
    //     useto: number;
    //     vecomment: string;
    // }
    function add_Venues(obj: object) {
        
        console.log(router)
        VenuesService.addVenues(obj).then((res: any) => {
            console.log("响应信息", res.data)
            if (res.data.code == 200 || res.data.code == 0) {
                ElMessage({ type: "success", message: res.data.msg })
                router.push({ name: "Changguan" })
            } else {
                ElMessage.error(res.data.msg)
            }
        }).catch((err: any) => {
            console.log("error", err)
            ElMessage("场馆添加请求失败")
        })
    }
    //删除
    function delete_id_venues( id: number,):any {
        console.log("111")
        const store = VenuesStore()
        VenuesService.deleteIdVenues(id).then((res:any)=>{
            console.log("请求数据",res.data.data);
            store.deleteList(res.data.data)
        })
    }

    return{
        page_Venues,
        delete_id_venues,
        add_Venues
    }
}
//查询
//  function page_Venues( limit: number, name: string, page: number,count:number):any {
//     console.log("111");
//     console.log(limit);
//     const store = VenuesStore()
//     VenuesService.getVenuesPageList(limit, name, page,count).then((res:any)=>{
//         console.log(res.data.data);
//         store.setList(res.data.data)
//     })
// }
// //新增
// // interface VenueInfo {
// //     address?: string;
// //     capacity?: number;
// //     createTime?: string;
// //     deleted?: string;
// //     email?: string;
// //     id: number;
// //     image: string;
// //     introduce: string;
// //     name: string;
// //     phone: number;
// //     state: number;
// //     updateTime: string;
// //     useto: number;
// //     vecomment: string;
// // }
// const router = useRouter()
// function add_Venues(obj: object) {
    
//     console.log(router)
//     VenuesService.addVenues(obj).then((res: any) => {
//         console.log("响应信息", res.data)
//         if (res.data.code == 200 || res.data.code == 0) {
//             ElMessage({ type: "success", message: res.data.msg })
//             router.push({ name: "Changguan" })
//         } else {
//             ElMessage.error(res.data.msg)
//         }
//     }).catch((err: any) => {
//         console.log("error", err)
//         ElMessage("场馆添加请求失败")
//     })
// }
// //删除
// function delete_id_venues( id: number,):any {
//     console.log("111")
//     const store = VenuesStore()
//     VenuesService.deleteIdVenues(id).then((res:any)=>{
//         console.log("请求数据",res.data.data);
//         store.deleteList(res.data.data)
//     })
// }
// export default {
//     page_Venues,
//     add_Venues,
//     delete_id_venues
// }